/**
 * CoffeeMilk (C) 2010 Amen Hamdan
 * 
 * See the NOTICE file distributed with this work for additional 
 * information regarding copyright ownership.  This file is licenses
 * to you under the Apache License, Version 2.0 (the "License"); you 
 * may not use this file except in compliance with the License.  You 
 * may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing 
 * permissions and limitations under the License.    
 * 
 */
package ameen.rtm.coffeemilk.ui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.io.File;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import org.apache.commons.io.FileUtils;

import ameen.rtm.coffeemilk.CoffeMilkApp;

public class AboutDialog extends JDialog {
	private static String fsNoticesString = null;  //  @jve:decl-index=0:
	
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel aboutPanel = null;
	private JScrollPane jScrollPane = null;
	private JLabel jLabel = null;
	private JPanel jPanel1 = null;
	private JLabel jLabel1 = null;
	private JTextArea jTextArea = null;
	/**
	 * @param owner
	 */
	public AboutDialog(Frame owner) {
		super(owner);
		if(fsNoticesString == null) {
			File file;
			try {
				file = new File(getClass().getResource("notices.txt").toURI());
				fsNoticesString = FileUtils.readFileToString(file);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(400, 300);
		this.setResizable(false);
		this.setTitle("About");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJTabbedPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.addTab("About CoffeeMilk", null, getAboutPanel(), null);
			jTabbedPane.addTab("Legal Notices", null, getJScrollPane(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes aboutPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getAboutPanel() {
		if (aboutPanel == null) {
			jLabel = new JLabel();
			jLabel.setText("(C) 2010 Amen Hamdan");
			jLabel.setToolTipText("");
			jLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel.setHorizontalAlignment(SwingConstants.CENTER);
			aboutPanel = new JPanel();
			aboutPanel.setLayout(new BorderLayout());
			aboutPanel.add(jLabel, BorderLayout.SOUTH);
			aboutPanel.add(getJPanel1(), BorderLayout.CENTER);
		}
		return aboutPanel;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			jScrollPane.setViewportView(getJTextArea());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setColumns(1);
			gridLayout.setRows(0);
			jLabel1 = new JLabel();
			jLabel1.setText("CoffeeMilk v" + CoffeMilkApp.APP_VERSION);
			jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel1.setFont(new Font("Dialog", Font.BOLD, 24));
			jPanel1 = new JPanel();
			jPanel1.setLayout(gridLayout);
			jPanel1.add(jLabel1, null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setText(fsNoticesString);
			jTextArea.setFont(new Font("Dialog", Font.PLAIN, 10));
			jTextArea.setLineWrap(true);
			jTextArea.setEditable(false);
			jTextArea.setSelectionStart(0);
			jTextArea.setSelectionEnd(0);
		}
		return jTextArea;
	}

}
